/**
 * Created by 121 on 2016/4/12.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'collection',
    'model',
    'dialog',
    'calendar',
    'highCharts'
], function ($, common, ready, template, Collection, Model, dialog, calendar, highCharts) {
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            this.event();
        },
        event: function () {
            var _this = this;
            var sql_data = function (sql, table_header) {
                $.ajax({
                    url: _global.url.api + 'data/sql',
                    type: 'get',
                    data: {sql: sql, table_header: table_header},
                    success: function (res) {
                        var data = res.data.datas;
                        var title = res.data.title;
                        console.log(data);
                        console.log(title);
                        for (var i = 0; i < title.length; i++) {
                            $('#title-item').append(template('title-tpl', {'item': title[i]}));
                        }
                        for (var i = 0; i < data.length; i++) {
                            $('#data-list').append(template('data-list-tpl'));
                            for (var item in data[i]) {
                                $('#data-list tr').eq(i).append(template('data-item-tpl', {'item':data[i][item]}));
                                console.log(template('data-item-tpl', {'item':data[i][item]}));
                                console.log('11111111111');
                            }
                        }
                    }
                });
            }
            //sql_data();
            $('#btn-search').click(function () {
                var table_header = $('#table-header').val();
                var sql = $('#sql').val();
                sql_data(sql, table_header);
                $('#table-header').val('');
                $('#sql').val('');
            })

        }
    };
    new index();
});